home *** CD-ROM | disk | FTP | other *** search
- Imports System.Drawing.Drawing2D
-
- Public Class FilledShapes
- Inherits System.Windows.Forms.Form
-
- #Region " Windows Form Designer generated code "
-
- Public Sub New()
- MyBase.New()
-
- 'This call is required by the Windows Form Designer.
- InitializeComponent()
-
- 'Add any initialization after the InitializeComponent() call
-
- End Sub
-
- 'Form overrides dispose to clean up the component list.
- Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
- If disposing Then
- If Not (components Is Nothing) Then
- components.Dispose()
- End If
- End If
- MyBase.Dispose(disposing)
- End Sub
- Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
- Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
- Friend WithEvents mnuRectangles As System.Windows.Forms.MenuItem
- Friend WithEvents mnuPolygons As System.Windows.Forms.MenuItem
- Friend WithEvents mnuBrushes As System.Windows.Forms.MenuItem
- Friend WithEvents mnuHatchBrushes As System.Windows.Forms.MenuItem
- Friend WithEvents mnuLinearGradientBrushes As System.Windows.Forms.MenuItem
- Friend WithEvents mnuTextureBrushes As System.Windows.Forms.MenuItem
- Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
- Friend WithEvents mnuPathGradientBrushes As System.Windows.Forms.MenuItem
- Friend WithEvents mnuRegions As System.Windows.Forms.MenuItem
- Friend WithEvents mnuALphaBlending As System.Windows.Forms.MenuItem
-
- 'Required by the Windows Form Designer
- Private components As System.ComponentModel.Container
-
- 'NOTE: The following procedure is required by the Windows Form Designer
- 'It can be modified using the Windows Form Designer.
- 'Do not modify it using the code editor.
- <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
- Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(FilledShapes))
- Me.mnuPathGradientBrushes = New System.Windows.Forms.MenuItem()
- Me.mnuRectangles = New System.Windows.Forms.MenuItem()
- Me.PictureBox1 = New System.Windows.Forms.PictureBox()
- Me.mnuPolygons = New System.Windows.Forms.MenuItem()
- Me.MainMenu1 = New System.Windows.Forms.MainMenu()
- Me.MenuItem1 = New System.Windows.Forms.MenuItem()
- Me.mnuBrushes = New System.Windows.Forms.MenuItem()
- Me.mnuHatchBrushes = New System.Windows.Forms.MenuItem()
- Me.mnuLinearGradientBrushes = New System.Windows.Forms.MenuItem()
- Me.mnuTextureBrushes = New System.Windows.Forms.MenuItem()
- Me.mnuRegions = New System.Windows.Forms.MenuItem()
- Me.mnuALphaBlending = New System.Windows.Forms.MenuItem()
- Me.SuspendLayout()
- '
- 'mnuPathGradientBrushes
- '
- Me.mnuPathGradientBrushes.Index = 6
- Me.mnuPathGradientBrushes.Text = "Path Gradient Brushes"
- '
- 'mnuRectangles
- '
- Me.mnuRectangles.Index = 0
- Me.mnuRectangles.Text = "Rectangles, Ellipses, Pie"
- '
- 'PictureBox1
- '
- Me.PictureBox1.Image = CType(resources.GetObject("PictureBox1.Image"), System.Drawing.Bitmap)
- Me.PictureBox1.Location = New System.Drawing.Point(424, 64)
- Me.PictureBox1.Name = "PictureBox1"
- Me.PictureBox1.Size = New System.Drawing.Size(144, 56)
- Me.PictureBox1.TabIndex = 0
- Me.PictureBox1.TabStop = False
- Me.PictureBox1.Visible = False
- '
- 'mnuPolygons
- '
- Me.mnuPolygons.Index = 1
- Me.mnuPolygons.Text = "Polygons"
- '
- 'MainMenu1
- '
- Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1})
- '
- 'MenuItem1
- '
- Me.MenuItem1.Index = 0
- Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuRectangles, Me.mnuPolygons, Me.mnuBrushes, Me.mnuHatchBrushes, Me.mnuLinearGradientBrushes, Me.mnuTextureBrushes, Me.mnuPathGradientBrushes, Me.mnuRegions, Me.mnuALphaBlending})
- Me.MenuItem1.Text = "Examples"
- '
- 'mnuBrushes
- '
- Me.mnuBrushes.Index = 2
- Me.mnuBrushes.Text = "Custom Brushes"
- '
- 'mnuHatchBrushes
- '
- Me.mnuHatchBrushes.Index = 3
- Me.mnuHatchBrushes.Text = "Hatch Brushes"
- '
- 'mnuLinearGradientBrushes
- '
- Me.mnuLinearGradientBrushes.Index = 4
- Me.mnuLinearGradientBrushes.Text = "Linear Gradient Brushes"
- '
- 'mnuTextureBrushes
- '
- Me.mnuTextureBrushes.Index = 5
- Me.mnuTextureBrushes.Text = "Textured Brushes"
- '
- 'mnuRegions
- '
- Me.mnuRegions.Index = 7
- Me.mnuRegions.Text = "Regions"
- '
- 'mnuALphaBlending
- '
- Me.mnuALphaBlending.Index = 8
- Me.mnuALphaBlending.Text = "Alpha Blending"
- '
- 'FilledShapes
- '
- Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
- Me.ClientSize = New System.Drawing.Size(624, 373)
- Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.PictureBox1})
- Me.Menu = Me.MainMenu1
- Me.Name = "FilledShapes"
- Me.Text = "Filled Shapes"
- Me.ResumeLayout(False)
-
- End Sub
-
- #End Region
-
- Private Sub mnuRectangles_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuRectangles.Click
- ' Wait until the menu closes.
- Threading.Thread.Sleep(400)
-
- ' Get a Graphics object from the current form and clear its background.
- Dim gr As Graphics = Me.CreateGraphics
- gr.Clear(Color.White)
-
- ' Draw a green filled rectangle.
- gr.FillRectangle(Brushes.Green, New Rectangle(20, 10, 200, 100))
-
- ' Draw a blue filled ellipse.
- gr.FillEllipse(Brushes.Blue, 20, 150, 200, 100)
-
- ' Draw a red pie (portion of an ellipse).
- gr.FillPie(Brushes.Red, 320, 150, 200, 100, -45, 90)
- ' Draw the remainder of the ellipse in pink.
- gr.FillPie(Brushes.Pink, 320, 150, 200, 100, 45, 270)
-
- ' Destroy the Graphics object.
- gr.Dispose()
- End Sub
-
- Private Sub mnuPolygons_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuPolygons.Click
- ' Wait until the menu closes.
- Threading.Thread.Sleep(400)
-
- Dim gr As Graphics = Me.CreateGraphics
- gr.Clear(Color.White)
-
- Dim points() As Point = {New Point(200, 100), New Point(300, 300), New Point(50, 170), _
- New Point(350, 170), New Point(100, 300)}
- gr.FillPolygon(Brushes.Gray, points, Drawing.Drawing2D.FillMode.Alternate)
-
- Dim points2() As Point = {New Point(600, 100), New Point(700, 300), New Point(450, 170), _
- New Point(750, 170), New Point(500, 300)}
- gr.FillPolygon(Brushes.GreenYellow, points2, Drawing.Drawing2D.FillMode.Winding)
-
- ' Destroy the Graphics object.
- gr.Dispose()
- End Sub
-
- Private Sub mnuBrushes_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuBrushes.Click
- ' Wait until the menu closes.
- Threading.Thread.Sleep(400)
-
- Dim gr As Graphics = Me.CreateGraphics
- gr.Clear(Color.White)
-
- ' Create a solid brush with a custom color and use it to fill a rectangle.
- Dim br As New SolidBrush(Color.FromArgb(128, 30, 100))
- gr.FillRectangle(br, New Rectangle(10, 10, 200, 100))
- ' Destroy the brush.
- br.Dispose()
-
- ' Destroy the Graphics object.
- gr.Dispose()
- End Sub
-
- Private Sub mnuHatchBrushes_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuHatchBrushes.Click
- ' Wait until the menu closes.
- Threading.Thread.Sleep(400)
-
- Dim gr As Graphics = Me.CreateGraphics
- gr.Clear(Color.White)
-
- Dim br1 As New HatchBrush(HatchStyle.BackwardDiagonal, Color.White, Color.Blue)
- gr.FillRectangle(br1, New Rectangle(10, 10, 200, 100))
- br1.Dispose()
-
- Dim br2 As New HatchBrush(HatchStyle.DarkVertical, Color.White, Color.Blue)
- gr.FillRectangle(br2, New Rectangle(10, 130, 200, 100))
- br2.Dispose()
-
- Dim br3 As New HatchBrush(HatchStyle.HorizontalBrick, Color.White, Color.Blue)
- gr.FillRectangle(br3, New Rectangle(10, 250, 200, 100))
- br3.Dispose()
-
- Dim br4 As New HatchBrush(HatchStyle.LargeCheckerBoard, Color.White, Color.Blue)
- gr.FillRectangle(br4, New Rectangle(310, 10, 200, 100))
- br4.Dispose()
-
- Dim br5 As New HatchBrush(HatchStyle.Wave, Color.White, Color.Blue)
- gr.FillRectangle(br5, New Rectangle(310, 130, 200, 100))
- br5.Dispose()
-
- Dim br6 As New HatchBrush(HatchStyle.Sphere, Color.White, Color.Blue)
- gr.FillRectangle(br6, New Rectangle(310, 250, 200, 100))
- br6.Dispose()
-
- ' Destroy the Graphics object.
- gr.Dispose()
- End Sub
-
- Private Sub mnuLinearGradientBrushes_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuLinearGradientBrushes.Click
- ' Wait until the menu closes.
- Threading.Thread.Sleep(400)
-
- Dim gr As Graphics = Me.CreateGraphics
- gr.Clear(Color.White)
-
- Dim br As New LinearGradientBrush(New Rectangle(0, 0, 200, 100), Color.Blue, Color.Black, Drawing2D.LinearGradientMode.ForwardDiagonal)
- gr.FillRectangle(br, 0, 0, 200, 100)
- gr.FillRectangle(br, 220, 0, 200, 100)
- br.Dispose()
-
- ' Destroy the Graphics object.
- gr.Dispose()
- End Sub
-
- Private Sub mnuTextureBrushes_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuTextureBrushes.Click
- ' Wait until the menu closes.
- Threading.Thread.Sleep(400)
-
- Dim gr As Graphics = Me.CreateGraphics
- gr.Clear(Color.White)
-
- Dim br1 As New TextureBrush(PictureBox1.Image)
- gr.FillRectangle(br1, New Rectangle(20, 20, 250, 150))
- br1.Dispose()
-
- Dim br2 As New TextureBrush(PictureBox1.Image, WrapMode.TileFlipY)
- gr.FillRectangle(br2, New Rectangle(300, 20, 250, 150))
- br2.Dispose()
-
- Dim br3 As New TextureBrush(PictureBox1.Image, WrapMode.TileFlipX)
- gr.FillRectangle(br3, New Rectangle(20, 220, 250, 150))
- br3.Dispose()
-
- Dim br4 As New TextureBrush(PictureBox1.Image, WrapMode.TileFlipXY)
- gr.FillRectangle(br4, New Rectangle(300, 220, 250, 150))
- br4.Dispose()
-
- ' Destroy the Graphics object.
- gr.Dispose()
- End Sub
-
- Private Sub mnuPathGradientBrushes_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuPathGradientBrushes.Click
- ' Wait until the menu closes.
- Threading.Thread.Sleep(400)
-
- Dim gr As Graphics = Me.CreateGraphics
- gr.Clear(Color.White)
-
- ' Define an elliptical path.
- Dim pa As New GraphicsPath()
- pa.AddEllipse(10, 10, 200, 100)
- ' Create the Brush shaped after the Path.
- Dim br As New PathGradientBrush(pa)
- br.CenterColor = Color.Yellow
- ' Define a one-element array of colors.
- Dim colors() As Color = {Color.Blue}
- br.SurroundColors = colors
- ' Paint the ellipse.
- gr.FillPath(br, pa)
- ' Destroy the brush and the path.
- br.Dispose()
- pa.Dispose()
-
- Dim pa2 As New GraphicsPath()
- Dim points() As Point = {New Point(300, 10), New Point(500, 10), New Point(500, 210), New Point(300, 210)}
- pa2.AddLines(points)
- pa2.CloseFigure()
- Dim br2 As New PathGradientBrush(pa2)
- br2.CenterColor = Color.Yellow
- br2.CenterPoint = New PointF(450, 60)
- Dim colors2() As Color = {Color.Blue, Color.Green, Color.Red, Color.Black}
- br2.SurroundColors = colors2
- gr.FillPath(br2, pa2)
- ' Destroy the brush and the path.
- br2.Dispose()
- pa2.Dispose()
-
- ' Destroy the Graphics object.
- gr.Dispose()
- End Sub
-
- Private Sub mnuRegions_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuRegions.Click
- ' Wait until the menu closes.
- Threading.Thread.Sleep(400)
-
- Dim gr As Graphics = Me.CreateGraphics
- gr.Clear(Color.White)
-
- ' Start with a square region
- Dim reg As New Region(New Rectangle(20, 20, 300, 300))
- ' Create a circular hole in it.
- Dim pa As New GraphicsPath()
- pa.AddEllipse(120, 120, 100, 100)
- reg.Exclude(pa)
- ' Add another smaller square in the center.
- reg.Union(New Rectangle(150, 150, 40, 40))
- ' Paint the region.
- gr.FillRegion(Brushes.Aquamarine, reg)
-
- ' use the Region as a clipping region.
- gr.SetClip(reg, CombineMode.Replace)
- ' Display many circles.
- Dim x As Integer, y As Integer, r As New Random()
- For x = 10 To 320 Step 40
- For y = 10 To 320 Step 40
- Dim br As New SolidBrush(Color.FromArgb(r.Next(0, 255), r.Next(0, 255), r.Next(0, 255)))
- gr.FillEllipse(br, x, y, 30, 30)
- br.Dispose()
- Next
- Next
-
- ' Destroy the Path and the Region.
- pa.Dispose()
- reg.Dispose()
- ' Destroy the Graphics object.
- gr.Dispose()
- End Sub
-
- Private Sub mnuAlphaBlending_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuALphaBlending.Click
- ' Wait until the menu closes.
- Threading.Thread.Sleep(400)
-
- ' Get a Graphics object from the current form and clear its background.
- Dim gr As Graphics = Me.CreateGraphics
- gr.Clear(Color.White)
-
- ' A solid green square.
- gr.FillRectangle(Brushes.Green, 20, 20, 200, 200)
- ' A semi-transparent red ellipse
- Dim br1 As New SolidBrush(Color.FromArgb(128, 255, 0, 0))
- gr.FillEllipse(br1, 120, 50, 200, 120)
- ' An even more transparent blue rectangle.
- Dim br2 As New SolidBrush(Color.FromArgb(30, 0, 0, 255))
- gr.FillRectangle(br2, 160, 80, 120, 200)
- ' A semi-transparent thick yellow ellipse.
- Dim p As New Pen(Color.FromArgb(128, 128, 128, 128), 5)
- gr.DrawEllipse(p, 100, 100, 200, 200)
-
- ' Destroy brushes and pens.
- br1.Dispose()
- br2.Dispose()
- p.Dispose()
-
- ' Destroy the Graphics object.
- gr.Dispose()
- End Sub
- End Class
-
-